# coding:utf-8
from django.db import models


# 关于我们
class About(models.Model):
    id = models.AutoField(primary_key=True)
    address = models.CharField(max_length=250, default='',verbose_name="网站地址")
    fax_number = models.CharField(max_length=250, default='',verbose_name="传真")
    record_number = models.CharField(max_length=250, default='',verbose_name="备案号")
    email = models.CharField(max_length=250, default='',verbose_name="email")
    logo_url = models.CharField(max_length=250, default='',verbose_name="logo url")
    phone = models.CharField(max_length=12, default='',verbose_name="网站联系电话")
    web_config = models.TextField(default='')
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'about'

# 后台菜单表
class Menus(models.Model):
    id = models.AutoField(primary_key=True)
    menu_name = models.CharField(max_length=250, default='')  # 菜单名称
    router_path = models.CharField(max_length=250, default='')  # 菜单路径
    sort = models.CharField(max_length=250, default='')  # 排序
    parent_id = models.CharField(max_length=250, default='')  # 排序
    router_icon = models.CharField(max_length=250, default='')  # 菜单对应的icon
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'menus'


# 角色表
class Role(models.Model):
    id = models.AutoField(primary_key=True)
    role_name = models.CharField(max_length=250, default='')  # 角色名称
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'role'

# 管理员
class AdminUsers(models.Model):
    id = models.AutoField(primary_key=True)
    real_name = models.CharField(max_length=250, default='')  # 网站地址
    name = models.CharField(max_length=250, default='')  # 登录账号名称
    phone = models.CharField(max_length=250, default='')  # 账号联系人
    password = models.CharField(max_length=250, default='')  # 备案号
    is_disable = models.CharField(max_length=12, default='')  # 是否被禁用
    theme = models.TextField(default='')  # 后台皮肤
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    role_id = models.OneToOneField(Role, on_delete=models.SET_NULL, null=True)  # 角色id
    class Meta:
        db_table = 'admin_users'

# 权限表
class RoleAccess(models.Model):
    id = models.AutoField(primary_key=True)
    role_id = models.ForeignKey(Role, on_delete=models.PROTECT)  # 角色id
    menu_id = models.ForeignKey(Menus, on_delete=models.PROTECT)  # 权限菜单id
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'role_access'

# 城市表
class Cities(models.Model):
    id = models.AutoField(primary_key=True)  # '省市区 ID'
    code = models.CharField(max_length=15, default='')  # 代码
    name = models.CharField(max_length=15, default='')  # 名称
    first = models.CharField(max_length=15, default='')  # 英文字母第一个
    parent_id = models.IntegerField()  # 父级 ID
    longitude = models.CharField(max_length=15, default='')  # 经度
    latitude = models.CharField(max_length=15, default='')  # 纬度
    level = models.IntegerField()  # 级别
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'cities'

# 轮播图
class Banner(models.Model):
    id = models.AutoField(primary_key=True)  #
    to_link = models.CharField(max_length=15, default='')  # 跳转地址
    url_type = models.CharField(max_length=15, default='')  # 1内部跳转,2跳转外部
    type = models.CharField(max_length=15, default='')  # 1滚动新闻,2 实验画册
    img_url = models.CharField(max_length=15, default='')  # 图片的地址
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'banner'

# 文章表
class Article(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=250, default='')  # 文章标题
    img_url = models.CharField(max_length=250, default='')  # 文章展示的url
    article_category_id = models.CharField(max_length=250, default='')  # 文章分类id
    is_recommend = models.IntegerField()  # 是否推荐,0不推荐,1推荐
    content = models.CharField(max_length=250, default='')  # 文章内容
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'article'

# 文章分类表
class ArticleCategory(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=250, default='')  # 文章分类名称
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'article_category'

# 用户充值表
class Recharge(models.Model):
    id = models.AutoField(primary_key=True)
    pay_status = models.IntegerField()  # 充值状态(0未充值,1充值成功)
    pay_time = models.DateTimeField(null=True)  # 付款时间
    pay_type = models.IntegerField()  # 1,支付宝(码支付),2微信,3后台手动充值,4后台手动减少
    order_no = models.CharField(max_length=250, default='')  # 充值订单号
    transaction_id = models.CharField(max_length=250, default='')  # 交易流水号
    money = models.DecimalField(decimal_places=2, max_digits=12)  # 充值金额
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'recharge'


# 短信配置表
class SmsConfig(models.Model):
    id = models.AutoField(primary_key=True)
    type = models.CharField(max_length=250, default='')  # 短信类型,1阿里大于
    sign_name = models.CharField(null=True,max_length=150)  # 短信签名
    app_key = models.CharField(max_length=100, default='')  #短信Key
    app_secret = models.CharField(max_length=100, default='')  # 短信秘钥
    msg_length = models.CharField(max_length=2, default=4)  # 短信长度
    status = models.IntegerField()  # 使用状态
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'sms_config'
# 短信发送记录表
class SmsRecord(models.Model):
    id = models.AutoField(primary_key=True)
    code = models.CharField(max_length=20, default='')  # 验证码
    mobile = models.CharField(null=True,max_length=20)  # 发送的手机号
    type = models.CharField(max_length=20, default='')  #发送类型,login, register ,forget
    status = models.IntegerField()  # 0有效,1失效
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'sms_record'


# 短信发送模板
class SmsTemplate(models.Model):
    id = models.AutoField(primary_key=True)
    sign_name = models.CharField(max_length=20, default='')  # 模板签名
    content = models.CharField(null=True,max_length=200)  # 发送的内容
    template_code = models.CharField(max_length=200, default='')  #模板Id
    type = models.IntegerField()  #模板类型,login, register ,forget
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'sms_template'
# 用户表
class Users(models.Model):
    user_id = models.AutoField(primary_key=True)
    parent_id = models.IntegerField()  # 父id
    weixin = models.CharField(max_length=50, default='')  # 微信
    nickName = models.CharField(max_length=50, default='')  # 微信昵称
    money = models.DecimalField(decimal_places=2, max_digits=12)  # 用户余额
    phone = models.CharField(max_length=20, default='')  # 用户手机号
    user_type = models.IntegerField()  # 用户类型
    content = models.CharField(null=True, max_length=200)  # 发送的内容
    is_disable = models.IntegerField()  # 是否被禁止
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'users'

# 用户金钱变动表
class UsersMoneyLog(models.Model):
    id = models.AutoField(primary_key=True)
    user_id = models.OneToOneField(Users, on_delete=models.PROTECT)  # 关联用户
    desc = models.CharField(max_length=250, default='')  # 金钱变动描述
    transaction_id = models.CharField(max_length=250, default='')  # 交易流水号
    status = models.IntegerField()  # 1 减少,2增加
    money = models.DecimalField(decimal_places=2, max_digits=12)  # 变动金额
    new_money = models.DecimalField(decimal_places=2, max_digits=12)  # 变动后的金额
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)
    deleted_at = models.DateTimeField(null=True)
    class Meta:
        db_table = 'users_money_log'